#pragma once
#include "primitives.h"
#include <math.h>


namespace DXBase
{
	public ref class DPI sealed
	{
	private:
		DPI();
	public:

		// return the minimum acceptable DPI, 25 for ~1 pixel per millimetre
		static property float MinDPI { float get() { return 25.0f; } }
		static property float InchToDIP { float get() { return 96.0f; } }
		static property float DisplayDPI { float get() { return Windows::Graphics::Display::DisplayProperties::LogicalDpi; } }

		// return a Device Independent Pixel size from a Device Dependent Pixel size
		static Windows::Foundation::Size GetDIP(float dpi, Windows::Foundation::Size s)
		{
			return Windows::Foundation::Size(GetDIP(dpi, s.Width), GetDIP(dpi, s.Height));
		}
		// return a Device Independent Pixel size from a Device Dependent Pixel size
		static Windows::Foundation::Size GetDIP(float dpi, USize s)
		{
			return Windows::Foundation::Size(GetDIP(dpi, (float)s.width), GetDIP(dpi, (float)s.height));
		}
		// return a Device Independent Pixel location from a Device Dependent Pixel location
		static Windows::Foundation::Point GetDIP(float dpi, Windows::Foundation::Point s)
		{
			return Windows::Foundation::Point(GetDIP(dpi, s.X), GetDIP(dpi, s.Y));
		}
		// return a Device Independent Pixel length from a Device Dependent Pixel length
		[Windows::Foundation::Metadata::DefaultOverload]
		static float GetDIP(float dpi, float value)
		{
			return InchToDIP * value / dpi;
		}

		// get a Device Dependent Pixel unsigned integer size from a Device Independent Pixel size
		static USize GetUDDP(float dpi, Windows::Foundation::Size s)
		{
			auto get = [dpi] (float value) -> uint32 { return static_cast<UINT32>(floor(DPI::GetDDP(dpi, value) + 0.5f)); };
			USize res = { get(s.Width), get(s.Height) };
			return res;
		}
		// return a Device Dependent Pixel size from a Device Independent Pixel size
		static Windows::Foundation::Size GetDDP(float dpi, Windows::Foundation::Size s)
		{
			return Windows::Foundation::Size(GetDDP(dpi, s.Width), GetDDP(dpi, s.Width));
		}
		// return a Device Dependent Pixel location from a Device Independent Pixel location
		static Windows::Foundation::Point GetDDP(float dpi, Windows::Foundation::Point s)
		{
			return Windows::Foundation::Point(GetDDP(dpi, s.X), GetDDP(dpi, s.Y));
		}
		// return a Device Dependent Pixel length from a Device Independent Pixel length
		[Windows::Foundation::Metadata::DefaultOverload]
		static float GetDDP(float dpi, float value)
		{
			return value * dpi / InchToDIP;
		}
	};
}